# 源地址

# 解码
# base = "http%3A%2F%2Fshp%2Eqpic%2Ecn%2Fishow%2F2735062915%2F1593417523%5F84828260%5F29743%5FsProdImgNo%5F8%2Ejpg%2F200"
# url = parse.unquote(base)
# print(url)

# 将后面的200变成0 可以转换成高清壁纸

# 获取图片url中的page参数 可以进行翻页


import requests
from urllib import parse
import pprint
from urllib.request import urlretrieve
import os

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
}

def get_images(data):
    images_urls = []
    for i in range(1, 9):
        images_url = parse.unquote(data.get(f'sProdImgNo_{i}')).replace('200', '0')
        images_urls.append(images_url)

    return images_urls


def main():
    page_url = "https://apps.game.qq.com/cgi-bin/ams/module/ishow/V1.0/query/workList_inc.cgi?" \
               "activityId=2735&sVerifyCode=ABCD&sDataType=JSON&iListNum=20&totalpage=0&page=0" \
               "&iOrder=0&iSortNumClose=1&iAMSActivityId=51991&_everyRead=true&iTypeId=2&iFlowId=267733&iActId=2735&iModuleId=2735&_=1593425574105"
    response = requests.get(page_url, headers=headers)

    json_dic = response.json()['List']
    for data in json_dic:
        new_url = get_images(data)
        image_name = parse.unquote(data.get('sProdName')).replace('1:1','').strip()

        # 文件名
        dirpath = os.path.join('images',image_name)
        os.mkdir(dirpath)

        # 图片名字
        for index,image_url in enumerate(new_url):
            urlretrieve(image_url,os.path.join(dirpath,'%s.jpg')% (index+1))
            print('下载成功%s'% (image_url))

# if __name__ == '__main__':
#     main()
